package com.shenwei.yingdaoguanli.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author wang
 * @Date 2024/10/21 9:59
 * @PackageName:com.easyjava.utils
 * @ClassName: DateUtils
 * @Description: TODO
 * @Version 1.0
 */
public class DateUtils {
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    public static final String YYYYMMDD_SLASH = "yyyy/MM/dd";
    public static final String YYYYMMDD_HH_MM_SLASH = "yyyy/MM/dd HH:mm";
    public static final String YYYYMMDD = "yyyyMMdd";


    public static String format(Date date, String pattern) {
        return new SimpleDateFormat(pattern).format(date);

    }
    public static Date parse(String dateStr, String pattern) {
        try {
            return new SimpleDateFormat(pattern).parse(dateStr);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }


    public static void main(String[] args) {
        String dateStr = "2024-10-21 09:59:59";
        Date date = parse(dateStr, YYYY_MM_DD);
        String pattern = YYYY_MM_DD;
        String result = format(date, pattern);
        System.out.println(result);
    }

}
